package com.chunfeng.lerunapplication.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;

/**
 * token解析工具类
 *
 * @author by 春风能解释
 * <p>
 * 2022/10/11
 */
public class TokenUtils {

    /**
     * 解析token
     *
     * @param token token字符
     */
    public static <T> T checkToken(String token, Class<T> tClass) {
        try {
            DecodedJWT decode = JWT.decode(token);
            return decode.getClaim("user").as(tClass);
        } catch (Exception e) {
            return null;
        }
    }

}
